#include <iostream>
#include <sys/ipc.h>
#include <sys/shm.h>
#include <cstring>
#include <unistd.h>
#include "comm.hpp"

int main()
{
    key_t key = GetKey();
    int shmid =  GetShm(key); //获取共享内存

    char* s = (char*)shmat(shmid, nullptr, 0);
    std::cout << "attach shm done" << std::endl;

    int fd = open(filename.c_str(), O_WRONLY);
    
    sleep(10);
    char c = 'a';
    for(; c <='z'; c++)
    {
        s[c-'a'] = c;
        std::cout << "write : " << c << " done" << std::endl;
        sleep(1);
        
        int code = 1;
        write(fd, &code, sizeof(4));
    }

    shmdt(s); //去关联
    std::cout << "detach shm done" << std::endl;
    close(fd);
    return 0;
}
